package edu.wpi.cs509.representation;

import java.io.ObjectStreamException;
import java.io.Serializable;

/** The team color choices available in the game. 
 * This class provides a TeamColor.RED and TeamColor.BLUE object that
 * is to be used where team color's are needed in other objects.
 * 
 * @author Jay Lubomirski
 * @see edu.wpi.cs509.representation.PlayerPiece
 */
public class TeamColor extends StrategoObjectBc implements Serializable {
	private static final long serialVersionUID = 1L; // version of structure for messages
	String colorName; // printable version of color
	boolean isRed; 
	
	private TeamColor(boolean red, String Name) {
			super(Name);
			isRed = red;
			colorName = Name;
	}
		
	/** 
	 * Test whether color is Red.
	 * @return true if color is red. 
	 */
	public boolean isRed() {
		return (isRed);
	}
		
	/**
	 * Returns textual representation of color. 
	 */
	public String toString() {
		return (colorName);
	}
	
	/**
	 * Resolve which singleton color should be used during deserialization
	 * @return Object Reference
	 * @throws ObjectStreamException
	 */
	private Object readResolve() throws ObjectStreamException {
		if (colorName.equals(RED.colorName)) {
			return RED;
		} else if (colorName.equals(BLUE.colorName)) {
			return BLUE;
		} else {
			return BOTH;
		}
	}

	
	/** 
	 * The one RED team color attribute. Use this object when a red team color is needed.
	 */
	public static final TeamColor RED = new TeamColor( true, "Red");

	/** 
	 * The one BLUE team color attribute. Use this object when a blue team color is needed.
	 */
	public static final TeamColor BLUE = new TeamColor( false, "Blue");
	
	/** 
	 * The one BOTH team color attribute. Use this object when both teams can do actions
	 * such as placing pieces, creating a client game for observers.
	 */
	public static final TeamColor BOTH = new TeamColor( false, "Both");

	/**
	 * Little helper to get "the other color"
	 * @param color - color you want the opposite of
	 * @return
	 */
	public static TeamColor getOppositeColor(TeamColor color) {
		if (color == TeamColor.BLUE) {
			return TeamColor.RED;
		} else {
			return TeamColor.BLUE;
		}
	}
	
};


